package com.tanhua.dubbo.api;

import com.tanhua.model.mongo.Questions;
import org.apache.dubbo.config.annotation.DubboService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@DubboService
public class QuestionsApiImpl implements QuestionsApi{
    @Autowired
    private MongoTemplate mongoTemplate;
    //根据问卷id 获取到相对应的题目集合
    @Override
    public List<Questions> findQuestions(ObjectId id) {

        Query query = Query.query(Criteria.where("questionnaireId").is(id));

        List<Questions> questions = mongoTemplate.find(query, Questions.class);

        return questions;
    }

    @Override
    public Questions findById(ObjectId id) {

        Query query = Query.query(Criteria.where("id").is(id));
        Questions questions = mongoTemplate.findOne(query, Questions.class);
        return questions;
    }
}
